package LogisticsSystem.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import LogisticsSystem.mapper.CargoMapper;
import LogisticsSystem.po.Cargo;
import LogisticsSystem.po.CargoExample;
import LogisticsSystem.po.CargoExample.Criteria;
import LogisticsSystem.service.CargoService;

/**
 * @author 作者 slim
 * @version 创建时间：2017年11月21日 下午3:01:25 类说明
 */
@Service
public class CargoServiceImpl implements CargoService {

	@Autowired
	CargoMapper cargoMaper;

	@Override
	public List<Cargo> getCargolist(Cargo cargo) {
		CargoExample cargoExample = new CargoExample();
		if (cargo != null) {
			Criteria criteria = cargoExample.createCriteria();
			criteria.andCargoIdEqualTo(cargo.getCargoId());
		}
		return cargoMaper.selectByExample(cargoExample);
	}

	@Override
	public int updateCargo(Cargo cargo) {
		return cargoMaper.updateByPrimaryKey(cargo);
	}

	@Override
	public int deleteCargo(Integer cargoId) {
		return cargoMaper.deleteByPrimaryKey(cargoId);
	}

	@Override
	public int insertCargos(Cargo cargo) {
		return cargoMaper.insert(cargo);
	}

	@Override
	public List<Cargo> selectCargoByName(String cargoName) {
		CargoExample cargoExample = new CargoExample();
		Criteria criteria = cargoExample.createCriteria();
		criteria.andCargoNameEqualTo(cargoName);
		return cargoMaper.selectByExample(cargoExample);
	}

	@Override
	public List<Cargo> selectCargoLowerCount(double count) {
		CargoExample cargoExample = new CargoExample();
		Criteria criteria = cargoExample.createCriteria();
		criteria.andCargoCountLessThan(count);
		return cargoMaper.selectByExample(cargoExample);
	}

	@Override
	public List<Cargo> selectCargoLikeName(String cargoName) {
		CargoExample cargoExample = new CargoExample();
		Criteria criteria = cargoExample.createCriteria();
		criteria.andCargoNameLike('%' + cargoName + '%');
		return cargoMaper.selectByExample(cargoExample);
	}

	@Override
	public Cargo getoneCargo(Integer id) {
		
		return cargoMaper.selectByPrimaryKey(id);
	}

}
